﻿using System;
using System.Collections.Generic;
using System.Text;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using Infragistics.Win.UltraWinEditors;
using System.Drawing;

namespace QLNHK.Controls
{
    public class EmptyGridCreationFilter : IUIElementCreationFilter
    {
        private string strText;
        public EmptyGridCreationFilter()
        {
            strText = "Chưa có dữ liệu";
        }
        public EmptyGridCreationFilter(string message)
        {
            strText = message;
        }
        public void AfterCreateChildElements(UIElement parent)
        {
            try
            {
                if (parent is UltraGridUIElement)
                {
                    UltraGrid grd = parent.GetContext(typeof(UltraGrid)) as UltraGrid;
                    if (grd.Rows.Count > 0)
                    {
                        return;
                    }
                    UltraTextEditor txt = new UltraTextEditor();
                    UltraTextEditorUIElement ui = new UltraTextEditorUIElement(txt);
                    parent.ChildElements.Add(ui);
                    if (txt.Appearance == null)
                    {
                        txt.Appearance = new Infragistics.Win.Appearance();
                    }
                    txt.Appearance.BackColor = Color.White;
                    txt.Appearance.BackColor2 = Color.FromArgb(181, 234, 253);
                    txt.Appearance.BackGradientStyle = GradientStyle.ForwardDiagonal;
                    txt.Appearance.FontData.Bold = DefaultableBoolean.True;
                    txt.Appearance.FontData.SizeInPoints = 10;

                    txt.Appearance.TextHAlign = HAlign.Center;
                    txt.Appearance.TextVAlign = VAlign.Middle;
                    txt.Appearance.ForeColor = Color.Black;
                    txt.Text = strText;

                    ui.Rect = parent.Rect;
                }
            }
            catch (Exception ex)
            {
                Logger.LocalLogger.Instance().WriteMessage(ex);
            }
        }

        public bool BeforeCreateChildElements(UIElement parent)
        {
            return false;
        }
    }
}
